1
จากโค้ดแบบดั้งเดิมสู่แอปพลิเคชันที่ใช้ปัญญาประดิษฐ์สร้างเนื้อหา
AI011Lesson 3
00:00

จากโค้ดแบบดั้งเดิมสู่แอปพลิเคชันที่ใช้ปัญญาประดิษฐ์สร้างเนื้อหา

ภูมิทัศน์ของการพัฒนาซอฟต์แวร์กำลังเปลี่ยนแปลงอย่างรุนแรง เราได้เปลี่ยนจากโปรแกรมที่กำหนดโดยคำสั่งที่เข้มงวด มาสู่การพัฒนาที่ยืดหยุ่นและขึ้นอยู่กับภาษาธรรมชาติ ปัญญาประดิษฐ์ที่สร้างเนื้อหา การโต้ตอบ

1. การทำลายห่วงโซ่คำสั่ง

คืออะไร: แอปพลิเคชันแบบดั้งเดิมอาศัยอินเทอร์เฟซผู้ใช้กราฟิก (GUI) ที่คงที่ หรือชุดคำสั่งเฉพาะที่ขึ้นอยู่กับภาษา หากผู้ใช้เบี่ยงเบนจากการป้อนข้อมูลที่คาดหวัง ระบบจะล้มเหลว

ทำไมจึงสำคัญ: แอปพลิเคชันที่ใช้ปัญญาประดิษฐ์สร้างเนื้อหาให้ความยืดหยุ่นในระดับที่ไม่เคยมีมาก่อน พวกเขาอนุญาตให้ผู้ใช้โต้ตอบด้วยภาษาธรรมชาติเพื่อให้บรรลุเป้าหมายที่ซับซ้อน โดยปรับตัวตามเจตนา ไม่ใช่เพียงแค่ไวยากรณ์

2. หลักการของความไม่แน่นอน

คืออะไร: ในโค้ดแบบดั้งเดิม $1 + 1$ จะเท่ากับ $2$ เสมอ นี่คือระบบที่แน่นอน โมเดลภาษาขนาดใหญ่ (LLM)แต่ในทางกลับกัน ทำงานบนพื้นฐานของความน่าจะเป็น

ทำงานอย่างไร: พวกเขาสามารถสร้างผลลัพธ์ที่แตกต่างกันแม้จะใช้คำขอเดียวกัน ความหลากหลายนี้ถูกควบคุมผ่านพารามิเตอร์เฉพาะ โดยเฉพาะอย่างยิ่ง อุณหภูมิ.

3. องค์ประกอบพื้นฐาน: โทเคน และ อุณหภูมิ

  • โทเคน: หน่วยพื้นฐานเชิงตัวเลขที่ใช้ในการประมวลผลข้อความโดยโมเดล คำต่างๆ จะถูกแบ่งออกเป็นหน่วยย่อยเหล่านี้
  • อุณหภูมิ: การตั้งค่า (ตั้งแต่ $0.0$ ถึง $1.0$) ที่ควบคุมความสุ่ม ค่าต่ำจะให้ผลลัพธ์ที่คาดเดาได้และเน้นประเด็น ค่าสูงจะส่งเสริมผลลัพธ์ที่สร้างสรรค์และหลากหลาย
ความปลอดภัยเป็นอันดับแรก
อย่าเขียนรหัส API ลงในโค้ดแอปพลิเคชันโดยตรง ควรใช้ตัวแปรสภาพแวดล้อม (เช่น) .env ไฟล์) เพื่อปกป้องทรัพยากรปัญญาประดิษฐ์ของคุณจากการเข้าถึงโดยไม่ได้รับอนุญาต
app.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
Why are Large Language Models (LLMs) described as "non-deterministic"?
Because they can produce different results for the same prompt every time.
Because they always return the exact same output for a given input.
Because they cannot run on standard computer processors.
Because they require quantum computing to function.
Question 2
Which parameter should you decrease if you want the AI output to be more predictable and less creative?
Max Tokens
Top-P
Temperature
Frequency Penalty
Challenge: Building a "Study Buddy"
Apply your knowledge to a real-world scenario.
You are building a "Study Buddy" application that must provide strictly factual definitions for students preparing for exams. The application will connect to an Azure OpenAI resource.
Task 1
Identify the optimal Temperature setting for this specific task.
Solution:
Set Temperature to 0.0 or 0.1. This minimizes randomness and ensures the model provides the most likely, factual, and consistent definitions rather than creative or hallucinated responses.
Task 2
How should you secure the application's sensitive connection data?
Solution:
Move the API_KEY from the main code file into an environment variable or a hidden .env file. Use os.getenv("AZURE_OPENAI_KEY") to retrieve it securely at runtime.